From 11feefc7711ec2309d90146c74340e605c04eff3 Mon Sep 17 00:00:00 2001 From: David Scott Date: Thu, 9 Oct 2014 10:17:28 +0100 Subject: [PATCH] xl: add 'xstrdup' next to 'xrealloc' Signed-off-by: David Scott Acked-by: Wei Liu Reviewed-by: Konrad Rzeszutek Wilk --- tools/libxl/xl_cmdimpl.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index 988ee28f7a..abe9ac63f1 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -300,6 +300,19 @@ static void *xrealloc(void *ptr, size_t sz) { return r; } +static char *xstrdup(const char *x) __attribute__ ((unused)); +static char *xstrdup(const char *x) +{ + char *r; + r = strdup(x); + if (!r) { + fprintf(stderr, "xl: Unable to strdup a string of length %zu.\n", + strlen(x)); + exit(-ERROR_FAIL); + } + return r; +} + #define ARRAY_EXTEND_INIT(array,count,initfn) \ ({ \ typeof((count)) array_extend_old_count = (count); \ -- 2.30.2